<?php
/**
 * Created By Project
 * Author: 陈东
 * Copyright：陈东
 * Source Code：陈东
 * Explain：I shall not authorize for any other commercial purposes, law breakers must be prosecuted.
 */
namespace Home\Model;
use Think\Model;

class BnModel extends Model{
    //protected $tablePrefix = 'hrma_';
    //protected $tableName = 'bn';

    //protected $_validate = array(
    //
    //);

    //获取所有视频
    static function getlist(){

        $bn = M('bn');
        $where['state'] = 1;
       // $where['year'] = 2017;
	   $where['year'] = 2017;
        $res = $bn->where($where)->order('bn_weight desc')->select();
        return $res;
    }

    //获取分类
    static function gettype(){

        $bntype = M('bntype');
        $res = $bntype->select();
        return $res;
    }

    //根据分类ID获取所属视频
    static function getlisttotypeid($type_id = null){

        $bn = M('bn');
        $where['state'] = 1;
        //$where['year'] = 2017;
		$where['year'] = 2017;
        $where['type_id'] = $type_id;
        $res = $bn->where($where)->order('bn_weight desc')->select();
        if($res){
            foreach($res as &$v){
                $v['video'] = self::getvideostr($res['bn_videopath']);
            }
        }
        return $res;
    }

    //根据分类ID获取当前分类的信息
    static function gettypetotypeid($id = null){

        $bntype = M('bntype');
        $res = $bntype->where(array('id'=>$id))->find();
        return $res;
    }

    //判断是否是数字
    static function isNum($n){
        return preg_match('/^\d*$/',$n);
    }

    //根据视频id获取所属视频信息
    static function getinfotovid($vid = null){

        $bn = M('bn');
        $where['state'] = 1;
        $where['year'] = 2017;
        $where['id'] = $vid;
        $res = $bn->where($where)->find();
        $res['video'] = self::getvideostr($res['bn_videopath']);
        return $res;
    }

    //返回视频地址,自动判断是pc还是mobile
    static function getvideostr($str = null){
        $res = null;
        if($str){
            $vurl = 'http://vf.hrtv.cn';
            $videoname = str_replace('" width','',getLetvArray($str,'putfile'));
            $original  = $videoname;
            if(ismobile()){
                //输出移动端视频
                if(strstr($str,"vf.hrtv.cn")){
                    $videoname = urldecode($original);
                    $videoname = mb_convert_encoding($videoname, "UTF-8", "GBK");
                    $res = $vurl."/video/".$videoname.".mp4";
                    $res = "<video style=\"background-color:#000;\" src=\"".$res."\" height=\"200\" width=\"100%\" controls=\"controls\" poster=\"\" webkit-playsinline=\"\"></video>";
                }
            }else{
                //PC视频
                $width = 650;
                $height = 425;
                $res = "<iframe frameborder=\"0\" scrolling=\"no\" src=\"".$vurl."/player/?fwh=".$width.",".$height."&putfile=".$original."\" width=\"".$width."\" height=\"".$height."\"></iframe>";
            }
        }
        return $res;
    }

    //浏览量
    static function visit($id = null){

        $bn = M('bn');
        $res = $bn->where(array('id'=>$id))->setInc('bn_pv');
        return $res;
    }


}